#!/bin/sh

BINFILES_TO_INSTALL="src/cmds/gwsubmit src/scheduler/gw_greedy_scheduler src/gwd/gwd"

#HOSTS="xeon32.vpn.local xeon16.vpn.local"
LOCALHOST="xeon80.vpn.local"
HOSTS="xeon32.vpn.local"

#
# Kill daemons
#
echo pkill gwd
pkill gwd
for host in $HOSTS; do
	echo ssh $host pkill gwd
	ssh $host pkill gwd
done

sleep 4

#
# Copy files
# 
for file in $BINFILES_TO_INSTALL; do
	echo cp $file $GW_LOCATION/bin
	cp $file $GW_LOCATION/bin

	for host in $HOSTS; do
		echo scp $file $host:$GW_LOCATION/bin
		scp $file $host:$GW_LOCATION/bin
	done
done


#
# Start daemons
#
echo gwd -cm
gwd -cm
for host in $HOSTS; do
	echo ssh $host gwd -cm
	ssh $host gwd -cm
done

#
# Set host and port
#
echo "$LOCALHOST 6725" > $GW_LOCATION/var/gwd.port
for host in $HOSTS; do
    ssh $host "echo \"$host 6725\" > $GW_LOCATION/var/gwd.port"
done
